//
//  HomeSegCell.swift
//  LeGou
//
//  Created by lxm on 2022/9/19.
//

import UIKit
import JXSegmentedView

class HomeSegCell: JXSegmentedBaseCell {
    open var dotView = UIView()
    
    let topLabel = ZMUtil.label(title: "", color: .black, font: UIFont.systemFont(ofSize: 16, weight: .medium))

    let bottomLabel = ZMUtil.label(title: "", color: UIColor.zm.color666666(), font: UIFont.systemFont(ofSize: 12, weight: .medium))

    let redBg = UIView().then({$0.backgroundColor = "#DC1826".zm.hex()})
    
    open override func commonInit() {
        super.commonInit()

        contentView.addSubview(redBg)
        contentView.addSubview(topLabel)
        contentView.addSubview(bottomLabel)

        topLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(8)
            make.centerX.equalToSuperview()
        }
        
        
        
        bottomLabel.snp.makeConstraints { make in
            make.top.equalTo(topLabel.snp.bottom).offset(6)
            make.centerX.equalToSuperview()
        }
        
        redBg.snp.makeConstraints { make in
            make.left.equalTo(bottomLabel.snp.left).offset(-8)
            make.right.equalTo(bottomLabel.snp.right).offset(8)
            make.top.equalTo(bottomLabel.snp.top).offset(-2)
            make.bottom.equalTo(bottomLabel.snp.bottom).offset(2)
        }
        
        
//        backgroundColor = .red
    }

    open override func layoutSubviews() {
        super.layoutSubviews()
        redBg.layoutIfNeeded()
        redBg.layer.cornerRadius = redBg.zm.height / 2
    }

    open override func reloadData(itemModel: JXSegmentedBaseItemModel, selectedType: JXSegmentedViewItemSelectedType) {
        super.reloadData(itemModel: itemModel, selectedType: selectedType )

        guard let myItemModel = itemModel as? HomeSegModel else {
            return
        }

        topLabel.text = myItemModel.topTitile
        topLabel.textColor = myItemModel.isSelected ? "#DC1826".zm.hex() : UIColor.black
        bottomLabel.textColor = myItemModel.isSelected ? UIColor.white : UIColor.zm.color666666()

        bottomLabel.text = myItemModel.bottomTilte
        redBg.isHidden = !myItemModel.isSelected
        
//        dotView.backgroundColor = myItemModel.dotColor
//        dotView.bounds = CGRect(x: 0, y: 0, width: myItemModel.dotSize.width, height: myItemModel.dotSize.height)
//        dotView.isHidden = !myItemModel.dotState
//        dotView.layer.cornerRadius = myItemModel.dotCornerRadius
        setNeedsLayout()
    }
}
